package org.paraj.misc;

import org.springframework.remoting.rmi.RmiProxyFactoryBean;

/**
 * Created by IntelliJ IDEA.
 * User: piotrga
 * Date: Nov 18, 2008
 * Time: 8:16:04 PM
 * To change this template use File | Settings | File Templates.
 */
public class RmiInvokerFactory {
    private boolean lookupOnStartup = false;

    public <T> T lookup(String name, Class<T> interface_){
        RmiProxyFactoryBean factoryBean = new RmiProxyFactoryBean();
        factoryBean.setServiceUrl(name);
        factoryBean.setServiceInterface(interface_);
        factoryBean.setLookupStubOnStartup(lookupOnStartup);
        factoryBean.setRefreshStubOnConnectFailure(true);
        factoryBean.afterPropertiesSet();
        return (T) factoryBean.getObject();
    }

    public RmiInvokerFactory lookupOnStartup(boolean lookupOnStartup) {
        this.lookupOnStartup = lookupOnStartup;
        return this;
    }
}
